package zhanghao;



import java.io.IOException;


import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class SourceAllFlowReduce  extends Reducer<Text, Text, Text, Text>{
	
	private Text outkey =new Text();
	private Text outval =new Text();
	public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException 
	{

		long uv = 0;
		long pv = 0;
	
		String[] temp = {};
		for(Text text : values){
			temp = text.toString().split("\001");
			if(temp.length>1){
				uv += Integer.parseInt(temp[0]);
				pv += Long.parseLong(temp[1]);
			}
		}
		
		
		outkey.set(key.toString());
		outval.set("cf"+"\t"+"pv"+"\t"+pv);
		context.write(outkey, outval);
		
		outkey.set(key.toString());
		outval.set("cf"+"\t"+"uv"+"\t"+uv);
		context.write(outkey, outval);		
	
	}
}
